﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SettingConfiguration_Storage.cs" company="DevDigital">
//   DevDigital
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Settings.NET
{
    using System;

    /// <summary>
    /// Settings configuration
    /// </summary>
    public partial class SettingConfiguration
    {
        /// <summary>
        /// The current settings storage
        /// </summary>
        private ISettingsStorage currentSettingsStorage;

        /// <summary>
        /// Sets the current storage
        /// </summary>
        /// <typeparam name="TStorage">The type of the storage.</typeparam>
        /// <returns>The setting configuration</returns>
        public ISettingConfiguration WithStorage<TStorage>() where TStorage : ISettingsStorage, new()
        {
            var storage = this.settingsProviderFactory.GetStorage<TStorage>();
            return this.WithStorage(storage);
        }

        /// <summary>
        /// Sets the current storage.
        /// </summary>
        /// <param name="settingsStorage">The settings storage.</param>
        /// <returns>The setting configuration</returns>
        public ISettingConfiguration WithStorage(ISettingsStorage settingsStorage)
        {
            if (settingsStorage == null)
            {
                throw new ArgumentNullException("settingsStorage", "No settings provider specified");
            }

            this.currentSettingsStorage = settingsStorage;
            return this;
        }
    }
}